-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add redundant broadcast elimination pass after stablehlo conversion. #1252
base: main
Are you sure you want to change the base?
Conversation
ModuleOp module = getOperation(); | ||
IRRewriter rewriter(&getContext()); | ||
|
||
module->walk([&](Operation *op) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can pattern match directly w/ walk
by writing:
module->walk([&](mlir::tt::ttir::BroadcastOp op) {
return; | ||
} | ||
|
||
if (op->getResult(0).getType() == op->getOperand(0).getType()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this was not what I expected the name RedundantBroadcastEliminationPass
to mean. We need a simple test demonstrating this case.
To me this implies that the broadcast is operating on a tensor that's already broadcasted in that dimension, but should this be illegal by construction?
@@ -7,6 +7,7 @@ | |||
|
|||
#ifdef TTMLIR_ENABLE_STABLEHLO | |||
#include "ttmlir/Conversion/ArithToStableHLO/ArithToStableHLO.h" | |||
#include "ttmlir/Conversion/RedundantBroadcastElimination/RedundantBroadcastElimination.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, we should make it a generic pass instead of StableHLO dependent pass. Other dialects may also require this optimization.
Stablehlo can introduce broadcast ops for cases that do not require shape conversion. This can introduce an error during conversion as multiple operands of the consumer might need to be folded. This pass removes the redundant broadcasts that prevents an error later.
Fixes #1235
Example:
After this pass: